At 11:59 +0200 on 15/3/99, Silvio Emanuel Barbosa de Macedo wrote:
> If there is an insert between my INSERT and SELECT, won't the counter be
> increased ? The only way I can understand this is the transaction locks
> inserts... so, in fact there could not exist another insert...
The counter is increased - but you get the last value *you* used, not the
other. It's more or less like this:
counter = 5; Process1 hidden variable = null; Process2 hidden var = null;
-- Process1 inserts a tuple, calling nextval.
counter = 6; Process1 hidden variable = 6;
-- Second process inserts a tuple.
counter = 7; Process1 hidden variable = 6. Process2 hidden var = 7;
-- Process1 now wants to know which number it entered, calling currval.
-- Currval takes the value in the hidden variable. It's 6.
-- Now suppose process1 makes another insertion. Then:
counter = 8; Process1 hidden variable = 8. Process2 hidden var = 8;
Do you understand? Whenever you make a call to currval, your process gets
the value thus retrieved and keeps it. The two operations are done
atomically (uncrementing and checking what value was taken), so it doesn't
actually matter when you make the call to currval - the correct value is
already available to you.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma